package wservice;

import java.io.UnsupportedEncodingException;
import java.util.SortedMap;

import org.apache.commons.lang.StringUtils;

import code.Coder;

public class ParamUtils {
	
	public String md5(String param) {
		try {
			return new String(Coder.encryptMD5(param.getBytes("utf-8"))) ;
		} catch (UnsupportedEncodingException canNotHappened) {
			
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}
	
	
	/**
	 * accessKey + params + timestamp => hmac
	 * md5 => encrypt by private key => hmac
	 * 
	 * 校验Hmac
	 * @param param
	 * @return
	 */
	public boolean validateHmac(RequestParam param) {
		String accessKey = param.getAccessKey();
		String hmac = param.getHmac();
		String timestamp = param.getTimestamp();
		if(StringUtils.isEmpty(accessKey) || StringUtils.isEmpty(hmac) || StringUtils.isEmpty(timestamp)) {
			return false ;
		}
		
		SortedMap<String, String> smap = param.getSerializableMap();
		for (String key : smap.keySet()) {
			
		}
		
		return false ;
	}

}
